package com.items.blog.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;
@Slf4j
//把拦截器添加到服务上，使之生效
@Configuration//识别拦截器
public class WebConfig implements WebMvcConfigurer {

    private static final List<String> excludepath = Arrays.asList(
            //配置拦截路径，这些不进行拦截
            "/user/login",
            "/**/*.html",//排除所有html
            "/pic/**",//排除pic
            "/js/**",//排除js
            "/css/**",//排除css
            "/blog-editormd/**"
    );
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                .excludePathPatterns(excludepath);
    }


        /*
            设置静态资源映射,实现头像图片上传
            @param registry
         */
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            log.info("开始进行静态资源映射...");
            registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
            registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
        }

}
